package common.servlet;

import java.sql.SQLException;

import msg.MessageManager;
import registration.RegistrationManager;
import user.LoginManager;

import common.dal.Transaction;

/**
 * A bundle of all the managers, using a single transaction
 * 
 * @author Gal Lalouche
 */
public class ManagersBundle implements AutoCloseable {
	private final Transaction			t;
	
	/**
	 * The MessageMananger this bundle works on
	 */
	public final MessageManager			mm;
	/**
	 * The RegistrationManager this bundle works on
	 */
	public final RegistrationManager	rm;
	/**
	 * The LoginManager this bundle works on
	 */
	public final LoginManager			lm;
	
	/**
	 * Creates a new bundle. A new transaction will be created for this bundle and all managers.
	 */
	public ManagersBundle() {
		t = new Transaction();
		lm = LoginManager.getNewInstance(t);
		mm = MessageManager.getNewInstance(t);
		rm = RegistrationManager.getNewInstance(t);
	}
	
	/**
	 * @see Transaction#commit()
	 * @throws SQLException
	 */
	public void commit() throws SQLException {
		t.commit();
	}
	
	/**
	 * @see Transaction#close()
	 */
	@Override
	public void close() {
		t.close();
	}
}
